package 二叉搜索树中第K小的元素;

import tree_node.TreeNode;

class Solution {
    public int count;
    public int ret;
    public int kthSmallest(TreeNode root, int k) {
        count = k;
        dfs(root);
        return ret;
    }

    public void dfs(TreeNode root){
        if(root == null || count == 0){
            return;
        }
        dfs(root.left);
        count--;
        if(count == 0){
            ret = root.val;
            return;
        }
        dfs(root.right);
    }
}